package com.naihe.anderson.sms.dbhelper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.naihe.anderson.sms.entity.CapitalInfo;
import com.naihe.anderson.sms.entity.RecordMoney;

public class RecordMoneyDBHelper extends SQLiteOpenHelper {

	private static final int DEFAULT_VERSION = 1;
	private static final String DB_NAME_PREFIX = "recordmoney_db";
	public static final String RECORDMONEY_TABLE_NAME = "recordmoney";
	public static final String CAPITALINFO_TABLE_NAME = "capitalInfo";
	
	public final static String[] recordmoney_projection = {
		RecordMoney.RMID,
		RecordMoney.MONEYNUM,
		RecordMoney.PROJECT,
		RecordMoney.PROJECTPIC,
		RecordMoney.CREATETIME,
		RecordMoney.OBJECTMEMBER,
		RecordMoney.REMARKS,
		RecordMoney.ACTIONTYPE,
		RecordMoney.LOATION
	};
	
	public final static String[] capitalInfo_projection = {
		CapitalInfo.CID ,
		CapitalInfo.NUMBER,
		CapitalInfo.EXPENDITURE_KEYS,
		CapitalInfo.INCOME_KEYS,
		CapitalInfo.CREATE_TIME
	};
	
	private final static String RECORDMONEY_TABLE_CREATE  = "CREATE TABLE IF NOT EXISTS "
			+ RECORDMONEY_TABLE_NAME
			+ "("
			+ RecordMoney.RMID 						+ " INTEGER PRIMARY KEY,"
			+ RecordMoney.MONEYNUM			 		+ " REAL,"
			+ RecordMoney.PROJECT 					+ " TEXT,"
			+ RecordMoney.PROJECTPIC 				+ " TEXT,"
			+ RecordMoney.CREATETIME 				+ " INTEGER,"
			+ RecordMoney.OBJECTMEMBER 				+ " TEXT,"
			+ RecordMoney.REMARKS 					+ " TEXT,"
			+ RecordMoney.ACTIONTYPE 				+ " INTEGER,"
			+ RecordMoney.LOATION 					+ " TEXT"
			+");";
	
	private final static String CAPITALINFO_TABLE_CREATE  = "CREATE TABLE IF NOT EXISTS "
			+ CAPITALINFO_TABLE_NAME
			+ "("
			+ CapitalInfo.CID 						+ " INTEGER PRIMARY KEY,"
			+ CapitalInfo.NUMBER 					+ " TEXT,"
			+ CapitalInfo.EXPENDITURE_KEYS 			+ " TEXT,"
			+ CapitalInfo.INCOME_KEYS 				+ " TEXT,"
			+ CapitalInfo.CREATE_TIME 				+ " INTEGER"
			+");";
	
	public RecordMoneyDBHelper(Context context) {
		super(context, DB_NAME_PREFIX+".db", null, DEFAULT_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(RECORDMONEY_TABLE_CREATE);
		db.execSQL(CAPITALINFO_TABLE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}

	public SQLiteDatabase openForWrite(String name)  throws Exception{ 
		return getWritableDatabase();
	}

	public SQLiteDatabase openForRead(String name) throws Exception{
		return getReadableDatabase();
	}
	
}
